
/**
 * 提交保存
 */
function roleFormSave() {
    let roleForm = $("#roleForm").serializeObject();
    let menuIdList = [];
    for (let check of tree.getChecked('userMenuTree')[0].children) {
        let menuId = {
            pid: check.id
        }
        menuIdList.push(menuId);
    }
    roleForm.permissions = menuIdList;
    $.DPost(ctx + "/role/c/saveOrUpdate", roleForm, headers,function (data) {
        if (data.code === '00000') {
            layer.msg("保存成功", {icon: 1, time: 2000}, function () {
                // 关闭当前页面
                parent.layer.close(parent.layer.getFrameIndex(window.name));
                // 刷新父页面table(连同查询条件)：
                parent.layui.table.reload('roleTable');
            });
        }else{
            layer.msg("保存失败", {icon: 1, time: 2000}, function () {
                // 关闭当前页面
                parent.layer.close(parent.layer.getFrameIndex(window.name));
                // 刷新父页面table(连同查询条件)：
                parent.layui.table.reload('roleTable');
            });
        }

    });
}

/**
 * 加载菜单
 */
function loadMenuTree() {
    let roleForm = $("#roleForm").serializeObject();
    let data = {
        'roleId': roleForm.roleId
    }
    //获取菜单数据
    $.DPost(ctx + "/permission/c/findUserMenuByRoleId?roleId="+roleForm.roleId, data, headers, function (data) {
        //数据说明：id对应id，title对应menuName，href对应menuPath
        let treeData = commonUtil.updateKeyForLayuiTree(data.data.permissionHave);
        // 存储所有菜单信息
        localStorage.setItem("permissionAll", JSON.stringify(data.data.permissionAll));
        //回显用户菜单
        treeData = commonUtil.checkedForLayuiTree(treeData, JSON.stringify(data.data.permissionAll));
        //开启节点操作图标
        tree.render({
            elem: '#userMenuTree'
            , id: 'userMenuTree'
            , data: [{
                title: '系统菜单根节点'
                , href: "/"
                , id: 0
                , spread: true
                , children: treeData
            }]
            , showCheckbox: true
        });
    });
}
